#include "teacher.h"
#include "ui_teacher.h"

teacher::teacher(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::teacher)
{
    ui->setupUi(this);
    setWindowFlags(Qt::Dialog);
    setFixedSize(556, 188);
}

teacher::~teacher()
{
    delete ui;

}

void teacher::set_tno(QString a)
{
    tno=a;
}

void teacher::on_pushButton_clicked()  //inquiry按钮点击触发
{

    QSqlQuery query1,query2,query3;
    query1.exec("select cno from teacher where tno='"+tno+"'");  //根据教师号查询所授课程号
    query1.next();
    QString cno=query1.value(0).toString();
    query2.exec("select cname,surplus from course where cno='"+cno+"'");  //根据课程号查询课程名称和剩余量
    query2.next();
    QString cname = query2.value(0).toString();
    QString surplus = query2.value(1).toString();
    ui->course->setText(ui->course->text()+cname);
    ui->surplus->setText(ui->surplus->text()+surplus);
    query3.exec("select sname from student where sno in (select sno from s_c where cno='"+cno+"')");  //根据课程号从选课表与学生表查选了这堂课的学生清单
    while(query3.next())
    {
        QString sname = query3.value(0).toString();
        ui->student->setText(ui->student->text()+" "+sname);
    }
}

void teacher::on_actionalter_password_triggered()  //修改密码按钮点击触发
{
    alt.set_type(1);
    alt.set_number(tno);  //传递教师号
    alt.show();
    this->close();
}
